package com.esaheki.flashcards.supportModel;

import java.util.ArrayList;

import javax.swing.tree.TreePath;
import com.esaheki.flashcards.classes.*;

public class UserTreeModel extends AbstractTreeModel {
	
	private ArrayList<User> userlist;
	
	public UserTreeModel(ArrayList<User> userlist) {
		this.userlist = userlist;
	}

	@SuppressWarnings("unchecked")
	public Object getChild(Object parent, int index) {
		if (parent instanceof User) {
			ArrayList<Category> catlist = ((User) parent).getCategories();
			return catlist.get(index);
		}
		else {
			return ((ArrayList<User>) parent).get(index);
		}
	}

	@SuppressWarnings("unchecked")
	public int getChildCount(Object parent) {
		if (parent instanceof User) {
			ArrayList<Category> catlist = ((User) parent).getCategories();
			return catlist.size();
		}
		else {
			return ((ArrayList<User>) parent).size();
		}
	}

	@SuppressWarnings("unchecked")
	public int getIndexOfChild(Object parent, Object child) {
		if (parent instanceof User) {
			ArrayList<Category> catlist = ((User) parent).getCategories();
			return catlist.indexOf(child);
		}
		else {
			return ((ArrayList<User>)parent).indexOf(child);
		}
	}

	public Object getRoot() {
		return userlist;
	}

	public boolean isLeaf(Object node) {
		return node instanceof Category;
	}

	public void valueForPathChanged(TreePath path, Object newValue) {
		// TODO Auto-generated method stub
		
	}


}
